from core.ai.engine import AIEngine
import os
import sys
import importlib.util
CONFIG_API_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../tools/config_api.py'))
spec = importlib.util.spec_from_file_location("config_api", CONFIG_API_PATH)
config_api = importlib.util.module_from_spec(spec)
sys.modules["config_api"] = config_api
spec.loader.exec_module(config_api)

import time
import asyncio

def warmup_cache():
    config = config_api.get_config()
    ai_engine = AIEngine(config)
    
    common_questions = [
        "你好",
        "你是谁",
        "你会做什么",
        "介绍一下你自己",
        "今天天气怎么样",
        "讲个笑话",
        "有什么好听的歌推荐吗",
        "你多大了",
        "你是真人吗",
        "谢谢",
        "再见"
    ]
    
    print("开始预热AI缓存...")
    start_time = time.time()
    
    for i, question in enumerate(common_questions):
        response = asyncio.run(ai_engine.get_ai_response(question))  # 异步调用
        print(f"{i+1}/{len(common_questions)}: Q: {question[:20]}... A: {response[:30]}...")
        time.sleep(0.5)  # 避免请求过快
    
    elapsed = time.time() - start_time
    print(f"缓存预热完成! 耗时: {elapsed:.2f}秒")

if __name__ == "__main__":
    warmup_cache()